package com.imooc.coupon.constant;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;
import java.util.stream.Stream;

/**
 * 优惠劵状态枚举值
 *
 * @Author Administrator
 * @Date 2021/11/1 21:09
 * @Version 1.0
 */
@Getter
@AllArgsConstructor
public enum CouponStatus {
    USEABLE("可用的", 1),
    USED("已经使用的", 2),
    EXPIRED("过期未使用的", 3);

    private String description;
    private Integer code;

    public static CouponStatus of(Integer code) {
        Objects.requireNonNull(code);
        return Stream.of(values())
                .filter(bean -> bean.getCode().equals(code))
                .findAny().orElseThrow(() -> new IllegalArgumentException(code + " is not Exitsts!"));
    }
}
